-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add snapping to ends of the gradient line #3732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
editor/src/messages/portfolio/document/overlays/utility_types_native.rs
Outdated
Show resolved
Hide resolved
editor/src/messages/portfolio/document/overlays/utility_types_native.rs
Outdated
Show resolved
Hide resolved
| let projection = ((end - start).angle_to(mouse - start)).cos() * start.distance(mouse) / start.distance(end); | ||
|
|
||
| if distance.abs() < SEGMENT_INSERTION_DISTANCE && (0. ..=1.).contains(&projection) { | ||
| if let Some(index) = gradient.clone().insert_stop(mouse, transform) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gradient.clone() is called twice and insert_stop is called twice. This can be simplified:
let mut new_gradient = gradient.clone();
if let Some(index) = new_gradient.insert_stop(mouse, transform) {
responses.add(DocumentMessage::StartTransaction);
transaction_started = true;
let mut selected_gradient = SelectedGradient::new(new_gradient, layer, document);
selected_gradient.dragging = GradientDragTarget::Step(index);
// No offset when inserting a new stop, it should be exactly under the mouse
selected_gradient.render_gradient(responses);
tool_data.selected_gradient = Some(selected_gradient);
dragging = true;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done .
|
This kind of snapping doesn't actually snap: capture_10_.mp4It would need to calculate the color stop position where the gradient line intersects the snapping target line and snap it to that position when the snap is active, since the whole point of a snap is to take the precise mouse movements surrounding a target and jump them all to the exact value. This also occurs when dragging an endpoint when Shift is held to snap to a 15° angle increment. Note that the Line tool's implementation of this same behavior does work as expected when you're dragging a line's endpoint and holding Shift or Ctrl to lock the angle: capture_11_.mp4The snapping tolerance for this scenario is more sane in the Line tool (smaller tolerance area) than it is for the Gradient tool (too large of a tolerance area, should match Line tool's behavior). This is something I'm willing to wait on for a followup PR, if you prefer. |
Closes #3261